package com.njwb.day15.zqzb.game;

import java.io.IOException;
import java.util.Scanner;


/**
 * 玩家类
 */
public class Player {
    //玩家姓名
    private  String name;
    //玩家级别号
    private int levelNo;
    //玩家的当前得分
    private int score;
    //开始时间
    private long startTime;
    //已用时间
    private long elapsedTime;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLevelNo() {
        return levelNo;
    }

    public void setLevelNo(int levelNo) {
        this.levelNo = levelNo;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public long getElapsedTime() {
        return elapsedTime;
    }

    public void setElapsedTime(long elapsedTime) {
        this.elapsedTime = elapsedTime;
    }

    //基本信息
    public String toString() {
        return "玩家"+this.name+",当前玩家的级别号为："+this.levelNo+",当前级别已用时间："+this.elapsedTime+",当前的得分为："+this.score;
    }


    //玩家玩游戏。。
    public void play() throws IOException {
        Scanner scanner = new Scanner(System.in);
        //入口
        Game game = new Game(this);
        System.out.println("请输入玩家姓名：");
        this.name=scanner.next();

        System.out.println("请输入练习的类型：1.字母2.数字");

        int type = scanner.nextInt();
        if(type==1) {
            game.setiGenStrategy(new AbcGenImpl());
        }else{
            game.setiGenStrategy(new NumberGenImpl());
        }

        //玩家一共要玩多少级别
        for(int i = 0 ;i<LevelParams.LEVELS.length;i++) {

            //记录开始时间
            this.setStartTime(System.currentTimeMillis());
            //升级了，初始化当前玩家的级别为1级
            this.levelNo = this.levelNo+1;
            //得分清零
            this.setScore(0);
            //每个级别玩多少次数
            for(int j =0 ; j<LevelParams.LEVELS[i].getStrTimes();j++) {
                //System.out.println(LevelParams.LEVELS[i].getLevelNo()+"级别--->"+(j+1)+"次数");
                String out = game.genString();
                System.out.println("系统输出："+out);
                System.out.print("请输入：");
                String in = scanner.next();
                game.printResult(out,in);
            }
        }
    }
}
